<template>
  <div class="login-container">
    <el-row type="flex" class="row-bg" justify="center">
      <h1>系统管理</h1>
  <!-- <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
  <el-col :span="6"><div class="grid-content bg-purple-light"></div></el-col>
  <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> -->
</el-row>
    <!-- <h1>系统管理</h1> -->

    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="0px" class="demo-ruleForm">
  <el-form-item  prop="pass">
    <el-input type="zh" v-model="ruleForm.pass" placeholder="账号" autocomplete="off"></el-input>
  </el-form-item>
  <p></p>
  <el-form-item prop="checkPass">
    <el-input type="password" v-model="ruleForm.checkPass" placeholder="密码" autocomplete="off"></el-input>
  </el-form-item>
<p></p>
  <el-form-item>
    <el-row type="flex" class="row-bg" justify="center">
      <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
</el-row>

  </el-form-item>
</el-form>
  </div>  
</template>

<script>
  export default {
    data() {
      var checkAge = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('年龄不能为空'));
        }
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error('请输入数字值'));
          } else {
            if (value < 18) {
              callback(new Error('必须年满18岁'));
            } else {
              callback();
            }
          }
        }, 1000);
      };
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入账号'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        // } else if (value !== this.ruleForm.pass) {
        //   callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
          pass: '',
          checkPass: '',
          // age: ''
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          age: [
            { validator: checkAge, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
           
          const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });  
        let User1={ 
          username:this.ruleForm.pass,
          password:this.ruleForm.checkPass
        }
        this.axios.post("/api/login.action",User1).then(data=>{
    
          if(data.data){
            loading.close();
            localStorage.setItem("name",User1.username)
        
            alert("登录成功")
            this.$router.push({path:"/home"})
          }else{
            loading.close();
            alert("登录失败")
          }
        })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style scoped>

.login-container {  
  border-radius:15px;
  background-clip: padding-box;
  margin: 180px auto;
  width: 350px;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
  /* display: flex;
  flex-direction: column;
  justify-content: center;
  align-content: center; */
}
</style>